Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid

Imports Phoenix.DataAccess
Imports Phoenix.Helpers

Namespace Forms.Controls

    Public Class BillClientEdit : Inherits FieldEditBase

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            'GridView.GroupFormat = "{0}: {1}"
        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents PopupEdit As DevExpress.XtraEditors.PopupContainerEdit
        Friend WithEvents PopupControl As DevExpress.XtraEditors.PopupContainerControl
        Friend WithEvents GridColumnFullName As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientIconRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        Friend WithEvents GridColumnPicture As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientGridControl As DevExpress.XtraGrid.GridControl
        Friend WithEvents ClientGridView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents GridColumnInSalon As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents GridColumnGender As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ClientGenderRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        Friend WithEvents ClientInSalonRI As DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.PopupEdit = New DevExpress.XtraEditors.PopupContainerEdit
            Me.PopupControl = New DevExpress.XtraEditors.PopupContainerControl
            Me.ClientGridControl = New DevExpress.XtraGrid.GridControl
            Me.ClientGridView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.GridColumnPicture = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientIconRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.GridColumnFullName = New DevExpress.XtraGrid.Columns.GridColumn
            Me.GridColumnGender = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientGenderRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Me.GridColumnInSalon = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ClientInSalonRI = New DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
            CType(Me.PopupEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.PopupControl.SuspendLayout()
            CType(Me.ClientGridControl, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientGridView, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientIconRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientGenderRI, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ClientInSalonRI, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'PopupEdit
            '
            Me.PopupEdit.Dock = System.Windows.Forms.DockStyle.Fill
            Me.PopupEdit.Location = New System.Drawing.Point(0, 0)
            Me.PopupEdit.Name = "PopupEdit"
            '
            'PopupEdit.Properties
            '
            Me.PopupEdit.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.PopupEdit.Properties.PopupControl = Me.PopupControl
            Me.PopupEdit.Size = New System.Drawing.Size(504, 20)
            Me.PopupEdit.TabIndex = 2
            '
            'PopupControl
            '
            Me.PopupControl.Controls.Add(Me.ClientGridControl)
            Me.PopupControl.Location = New System.Drawing.Point(16, 40)
            Me.PopupControl.Name = "PopupControl"
            Me.PopupControl.Size = New System.Drawing.Size(296, 192)
            Me.PopupControl.TabIndex = 4
            '
            'ClientGridControl
            '
            Me.ClientGridControl.Dock = System.Windows.Forms.DockStyle.Fill
            '
            'ClientGridControl.EmbeddedNavigator
            '
            Me.ClientGridControl.EmbeddedNavigator.Name = ""
            Me.ClientGridControl.Location = New System.Drawing.Point(0, 0)
            Me.ClientGridControl.MainView = Me.ClientGridView
            Me.ClientGridControl.Name = "ClientGridControl"
            Me.ClientGridControl.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.ClientIconRI, Me.ClientGenderRI, Me.ClientInSalonRI})
            Me.ClientGridControl.Size = New System.Drawing.Size(296, 192)
            Me.ClientGridControl.TabIndex = 4
            Me.ClientGridControl.Text = "GridControl1"
            '
            'ClientGridView
            '
            Me.ClientGridView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.GridColumnPicture, Me.GridColumnFullName, Me.GridColumnGender, Me.GridColumnInSalon})
            Me.ClientGridView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus
            Me.ClientGridView.GridControl = Me.ClientGridControl
            Me.ClientGridView.Name = "ClientGridView"
            Me.ClientGridView.OptionsBehavior.AllowIncrementalSearch = True
            Me.ClientGridView.OptionsDetail.EnableMasterViewMode = False
            Me.ClientGridView.OptionsView.ShowGroupPanel = False
            Me.ClientGridView.OptionsView.ShowIndicator = False
            '
            'GridColumnPicture
            '
            Me.GridColumnPicture.ColumnEdit = Me.ClientIconRI
            Me.GridColumnPicture.FieldName = "Gender"
            Me.GridColumnPicture.Name = "GridColumnPicture"
            Me.GridColumnPicture.Options = CType(((DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.GridColumnPicture.VisibleIndex = 0
            Me.GridColumnPicture.Width = 20
            '
            'ClientIconRI
            '
            Me.ClientIconRI.AutoHeight = False
            Me.ClientIconRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ClientIconRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", "M", 7), New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", "F", 30)})
            Me.ClientIconRI.Name = "ClientIconRI"
            '
            'GridColumnFullName
            '
            Me.GridColumnFullName.Caption = "Full Name"
            Me.GridColumnFullName.FieldName = "FullName"
            Me.GridColumnFullName.Name = "GridColumnFullName"
            Me.GridColumnFullName.Options = CType(((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.GridColumnFullName.VisibleIndex = 1
            Me.GridColumnFullName.Width = 194
            '
            'GridColumnGender
            '
            Me.GridColumnGender.Caption = "Gender"
            Me.GridColumnGender.ColumnEdit = Me.ClientGenderRI
            Me.GridColumnGender.FieldName = "Gender"
            Me.GridColumnGender.Name = "GridColumnGender"
            Me.GridColumnGender.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.GridColumnGender.VisibleIndex = 2
            Me.GridColumnGender.Width = 60
            '
            'ClientGenderRI
            '
            Me.ClientGenderRI.AutoHeight = False
            Me.ClientGenderRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ClientGenderRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Male", "M", -1), New DevExpress.XtraEditors.Controls.ImageComboBoxItem("Female", "F", -1)})
            Me.ClientGenderRI.Name = "ClientGenderRI"
            '
            'GridColumnInSalon
            '
            Me.GridColumnInSalon.Caption = "In"
            Me.GridColumnInSalon.ColumnEdit = Me.ClientInSalonRI
            Me.GridColumnInSalon.FieldName = "InOffice"
            Me.GridColumnInSalon.Name = "GridColumnInSalon"
            Me.GridColumnInSalon.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.GridColumnInSalon.SortIndex = 0
            Me.GridColumnInSalon.SortOrder = DevExpress.Data.ColumnSortOrder.Descending
            Me.GridColumnInSalon.VisibleIndex = 3
            Me.GridColumnInSalon.Width = 20
            '
            'ClientInSalonRI
            '
            Me.ClientInSalonRI.AutoHeight = False
            Me.ClientInSalonRI.Name = "ClientInSalonRI"
            '
            'BillClientEdit
            '
            Me.Controls.Add(Me.PopupControl)
            Me.Controls.Add(Me.PopupEdit)
            Me.Name = "BillClientEdit"
            Me.Size = New System.Drawing.Size(504, 296)
            CType(Me.PopupEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            Me.PopupControl.ResumeLayout(False)
            CType(Me.ClientGridControl, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientGridView, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientIconRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientGenderRI, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ClientInSalonRI, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region " Field Editor Behavior "
        Public Overrides ReadOnly Property FieldView() As DevExpress.XtraEditors.PopupContainerEdit
            Get
                Return PopupEdit
            End Get
        End Property

        Public Overrides ReadOnly Property GridView() As DevExpress.XtraGrid.Views.Grid.GridView
            Get
                Return ClientGridView
            End Get
        End Property

        Public Overrides ReadOnly Property PrimaryColumn() As DevExpress.XtraGrid.Columns.GridColumn
            Get
                Return GridColumnFullName
            End Get
        End Property


        Public Overrides ReadOnly Property Icon() As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Get
                Return ClientIconRI
            End Get
        End Property

        Public Overrides ReadOnly Property IconColumn() As DevExpress.XtraGrid.Columns.GridColumn
            Get
                Return GridColumnPicture
            End Get
        End Property

        Public Overrides ReadOnly Property PopupWindow() As DevExpress.XtraEditors.PopupContainerControl
            Get
                Return PopupControl
            End Get
        End Property

#End Region

#Region " Event Handlers "
        Private Sub Control_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If DesignMode Then Return

            ClientGridControl.DataSource = New DataView(AppDataLayer.Clients)
            'GridColumnInSalon.FilterInfo = New ColumnFilterInfo(True)

        End Sub


        Private Sub PopupEdit_FocusedRowChanged(ByVal Sender As Object, ByVal e As DevExpress.XtraEditors.Controls.QueryDisplayTextEventArgs) Handles PopupEdit.QueryDisplayText
            If e.EditValue Is Nothing Then
                e.DisplayText = Res.BillSelectClient
            Else
                e.DisplayText = CType(e.EditValue, DataSetData.Client).FullName
            End If
        End Sub

#End Region

#Region " Internals "
        Private ReadOnly Property CurrentClient() As DataSetData.Client
            Get
                If IsInvalidRowHandle(GridView.FocusedRowHandle) Then Return Nothing
                Dim eRowView As DataRowView = CType(GridView.GetRow(GridView.FocusedRowHandle), DataRowView)
                If eRowView Is Nothing Then Return Nothing
                Return eRowView.Row
            End Get
        End Property

#End Region

    End Class

End Namespace